#include <stdio.h>
#include<stdio.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <linux/in.h>  //sockaddr_in
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	int sockfd,acceptfd;
	sockfd=socket(AF_INET,SOCK_STREAM,0);
	if(sockfd<0)
	{
		perror("socket err");
		exit(-1);
	}
	struct sockaddr_in serveraddr;
	serveraddr.sin_family=AF_INET;
	serveraddr.sin_port=htons(atoi(argv[2]));
	serveraddr.sin_addr.s_addr=inet_addr(argv[1]);
	socklen_t serverlen=sizeof(serveraddr);

	if(bind(sockfd,(struct sockaddr *)&serveraddr,serverlen)<0)
	{
		perror("bind errr");
		exit(-1);
	}
	printf("bind ok\n");

	if(listen(sockfd,8)<0)
	{
		perror("listen errr");
		exit(-1);
	}
	printf("listen ok\n");

	char buf[128]={0};
	acceptfd=accept(sockfd,NULL,NULL);
	printf("acceptfd ok.\n");
	while(1)
	{
		recv(acceptfd,buf,sizeof(buf),0);
		printf("buf= %s\n",buf);
	}
	close(sockfd);
	close(acceptfd);
	return 0;
}
